package com.marcowu.study.spb.tracing.manager;

import com.marcowu.study.spb.tracing.client.MyClient;
import com.marcowu.study.spb.tracing.zipkin.TraceUtil;
import io.opentracing.Scope;
import io.opentracing.Tracer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SampleManager {

  private static Logger s_logger = LoggerFactory.getLogger(SampleManager.class);

  private Tracer tracer = TraceUtil.getZipkinTracer("SampleManager");

  @Autowired
  private MyClient client;

  public String sayBye() throws Exception {
    try (Scope scope = tracer.buildSpan("sayBye")
            .startActive(true)) {
      scope.span().setTag("bye", "opentracing");
      return client.httpGet("zipkinTest/tracing/sayBye");
    }
  }

  public String sayHello() throws Exception {
    try (Scope scope = tracer.buildSpan("SayHello")
            .startActive(true)) {
      scope.span().setTag("hello", "opentracing");
      return client.httpGet("zipkinTest/tracing/sayHello");
    }
  }

  public void bye() {
    try (Scope scope = tracer.buildSpan("bye")
            .startActive(true)) {
      scope.span().setTag("bye", "opentracing");
      System.out.println("bye");
    }

  }

  public void hello() {
    try (Scope scope = tracer.buildSpan("hello")
            .startActive(true)) {
      scope.span().setTag("hello", "opentracing");
      System.out.println("hello");
    }
  }


}
